﻿using DevComponents.DotNetBar;
using Kimd.Common;
using Kimd.Machine;
using Kimd.Motion;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WorkStation.Common;

namespace WorkStation.UI
{
    public partial class FormSingleAxisMoveStep : Office2007Form
    {
        public List<string> PointNames;
        public Step CurrentStep { get; set; }
        public FormSingleAxisMoveStep(Step step, List<string> pointNames)
        {
            InitializeComponent();
            this.CurrentStep = step;
            this.PointNames = pointNames;
            this.EnableGlass = false;
        }

        private void FormSingleAxisMoveStep_Load(object sender, EventArgs e)
        {
            cB_AxisName.Items.Clear();
            cB_AxisName.Items.AddRange(SingletonProvider<MachineResource>.Instance.MachineAxis.Keys.ToArray());
            cB_PointNames.Items.Clear();
            cB_PointNames.Items.AddRange(PointNames.ToArray());

            if(!string.IsNullOrEmpty((CurrentStep as SingleAxisMoveStep).PointName))
            {
                cB_PointNames.SelectedIndex = cB_PointNames.Items.IndexOf((CurrentStep as SingleAxisMoveStep).PointName);
            }
            if(!string.IsNullOrEmpty((CurrentStep as SingleAxisMoveStep).AxisName))
            {
                cB_AxisName.SelectedIndex = cB_AxisName.Items.IndexOf((CurrentStep as SingleAxisMoveStep).AxisName);
            }
        }

        private void btn_Confirm_Click(object sender, EventArgs e)
        {
            if(cB_PointNames.SelectedIndex == -1)
            {
                SystemInfo.ShowToastInfo(this, "选择需要运动到的点位", true);
                return;
            }
            if (cB_AxisName.SelectedIndex == -1)
            {
                SystemInfo.ShowToastInfo(this, "选择需要运动到的轴", true);
                return;
            }
            (CurrentStep as SingleAxisMoveStep).AxisName = cB_AxisName.Text;
            (CurrentStep as SingleAxisMoveStep).PointName = cB_PointNames.SelectedItem.ToString();
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
